package com.etc.controller;

import com.etc.pojo.History;
import com.etc.pojo.User;
import com.etc.pojo.Video;
import com.etc.service.HistoryPersonageService;
import com.etc.service.VideoPersonageService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("HistoryPersonageController")
public class HistoryPersonageController {

    @Autowired
    HistoryPersonageService historyPersonageService;

    @ResponseBody
    @RequestMapping(value = "queryAllHistoryByUserId")
    public PageInfo<History> queryAllHistoryByUserId(@RequestParam(value = "date", defaultValue = "0" ) Integer date,
                                                     @RequestParam(value = "pageNum", defaultValue = "1")  Integer pageNum,
                                                     HttpSession session) {
        User user = (User)session.getAttribute("user");
        PageInfo<History> historyPageInfo = historyPersonageService.queryAllHistoryByUserId(user.getUserId(), date, pageNum);
        return historyPageInfo;
    }

    @ResponseBody
    @RequestMapping(value = "deleteHistoryByVideoId")
    public boolean deleteHistoryByVideoId(@RequestParam(value = "historyId")  Integer historyId) {
        boolean leep = historyPersonageService.deleteHistoryByVideoId(historyId);
        return leep;
    }
}
